<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //使用js主动下载
        function download(){
            fetch("http://127.0.0.1:8000/downloadFile", {
                "headers": {
                    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
                    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
                    "cache-control": "no-cache",
                    "pragma": "no-cache",
                    "sec-ch-ua": "\"Chromium\";v=\"142\", \"Microsoft Edge\";v=\"142\", \"Not_A Brand\";v=\"99\"",
                    "sec-ch-ua-mobile": "?1",
                    "sec-ch-ua-platform": "\"Android\"",
                    "sec-fetch-dest": "document",
                    "sec-fetch-mode": "navigate",
                    "sec-fetch-site": "none",
                    "sec-fetch-user": "?1",
                    "upgrade-insecure-requests": "1"
                },
                "body": null,
                "method": "GET"
                }).then(res=>{
                    let filename = res.headers.get("filename")
                    res.blob().then(blob=>{
                    let url = window.URL.createObjectURL(blob)
                    let downloadA = document.createElement("a")
                    document.body.appendChild(downloadA)
                    downloadA.setAttribute("href",url)
                    downloadA.setAttribute("download",filename)
                    downloadA.click()
                    document.body.removeChild(downloadA)
                    window.URL.revokeObjectURL(url)
                })
                });
        }
    </script>
    <a href="download.html" download="download.html">下载文件</a>
    <button onclick="download()">使用Js下载文件</button>
</body>
</html>